/*
 * @Author: 李金深 2896583081@qq.com
 * @Date: 2023-05-22 14:45:06
 * @LastEditors: 李金深
 * @LastEditTime: 2024-05-05 12:43:25
 * @FilePath: index.js
 * @Description:路由配置
 */
import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/login/login.vue'
import Home from '@/views/home/home.vue'

export const MenuRouter = {
  path: '/home',
  component: Home,
  redirect: '/home/dashboard',
  children: [
    {
      path: 'dashboard',
      component: () => import('@/views/dashboard/dashboard.vue'),
      meta: {
        auth: true,
        isMenu: true,
        icon: 'dataIcon'
      }
    },
    {
      path: 'device',
      redirect: '/home/device/deviceList',
      meta: {
        auth: true,
        isMenu: true,
        icon: 'deviceIcon'
      },
      children: [
        {
          path: 'deviceList',
          component: () => import('@/views/device/device.vue'),
          meta: {
            auth: true,
            isMenu: true
          }
        },
        {
          path: 'deviceDetail',
          component: () => import('@/views/device/deviceDetail.vue'),
          meta: {
            auth: true,
            isMenu: false
          }
        },
        {
          path: 'upgradeManage',
          component: () => import('@/views/device/upgradeManage.vue'),
          meta: {
            auth: true,
            isMenu: true
          }
        },
        {
          path: 'topology',
          component: () => import('@/views/device/topology.vue'),
          meta: {
            auth: true,
            isMenu: true
          }
        }
      ]
    },
    {
      path: 'alarm',
      redirect: '/home/alarm/alarmList',
      meta: {
        auth: true,
        isMenu: true,
        icon: 'alarmIcon',
        size: 26
      },
      children: [
        {
          path: 'alarmList',
          component: () => import('@/views/alarm/alarm.vue'),
          meta: {
            auth: true,
            isMenu: true
          }
        },
        {
          path: 'alarmSetting',
          component: () => import('@/views/alarm/alarmSetting.vue'),
          meta: {
            auth: true,
            isMenu: true
          }
        },
        {
          path: 'alarmNotify',
          component: () => import('@/views/alarm/alarmNotify.vue'),
          meta: {
            auth: true,
            isMenu: true
          }
        }
      ]
    },
    {
      path: 'permission',
      redirect: '/home/permisson/users',
      meta: {
        auth: true,
        isMenu: true,
        icon: 'permissionIcon'
      },
      children: [
        {
          path: 'users',
          component: () => import('@/views/permission/users.vue'),
          meta: {
            auth: true,
            isMenu: true
          }
        },
        {
          path: 'roles',
          component: () => import('@/views/permission/roles.vue'),
          meta: {
            auth: true,
            isMenu: true
          }
        }
      ]
    },
    {
      path: 'system',
      redirect: '/home/system/backup',
      meta: {
        auth: true,
        isMenu: true,
        icon: 'systemIcon'
      },
      children: [
        {
          path: 'backup',
          component: () => import('@/views/system/backup.vue'),
          meta: {
            auth: true,
            isMenu: true
          }
        },
        {
          path: 'log',
          component: () => import('@/views/system/log.vue'),
          meta: {
            auth: true,
            isMenu: true
          }
        }
      ]
    },
    {
      path: 'profile',
      component: () => import('@/views/profile/profile.vue'),
      meta: {
        auth: true,
        isMenu: false
      }
    }
  ]
}

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/home'
    },
    {
      path: '/login',
      component: Login
    },
    MenuRouter,
    {
      path: '/:pathMatch(.*)',
      // path: '/:pathMatch(.*)*',
      component: () => import('@/views/error/notFound.vue')
    }
  ]
})
router.beforeEach((to, from, next) => {
  // if (to.meta.auth) {
  //   let token = localStorage.getItem('USER_TOKEN')
  //   if (token) {
  //     if (from.path == '/email/write') {
  //       mitt.emit('pageJump', next)
  //     } else {
  //       next()
  //     }
  //   } else {
  //     mitt.emit('permissionCheckError')
  //   }
  // } else {
  //   next()
  // }
  next()
  document.documentElement.scrollTop = 0
})
export default router
